package parser;

import java.io.StringWriter;
import java.util.ArrayList;
import java.util.List;

import org.jrubyparser.NodeVisitor;
import org.jrubyparser.ast.*;
import org.jrubyparser.rewriter.ReWriteVisitor;

public class RubyVisitor implements NodeVisitor{

	private static Storage storage = Storage.getInstance();
	private static ControlFlowGraph cfg;
	private static CFGNode cfgNode;
	private static String className, methodName, fileName;
	private static List<Method> methods;
	private static Method method;
	private static String key, mvc, code="";
	
	public static String getCode() {
		return code;
	}

	public static void setCode(String code) {
		RubyVisitor.code = code;
	}

	public void visit(Node node)
	{
		//System.out.println("visit: "+node);
		RubyVisitor visitor = new RubyVisitor();
		node.accept(visitor);
	}
	
	public CFGNode getCfgNode() {
		return cfgNode;
	} 

	public void setCfgNode(CFGNode cfgNode) {
		RubyVisitor.cfgNode = cfgNode;
	}

	public static ControlFlowGraph getCfg() {
		return cfg;
	}

	public static void setCfg(ControlFlowGraph cfg) {
		RubyVisitor.cfg = cfg;
	}

	public static String getKey() {
		return key;
	}

	public void setKey(String key) {
		String[] tempMvc=key.split(";");
		RubyVisitor.fileName=tempMvc[0];
		RubyVisitor.mvc=tempMvc[1];
		RubyVisitor.key = key;
	}

	public List<Method> getMethods() {
		return methods;
	}
	
	public void setMethods(List<Method> methods) {
		RubyVisitor.methods = methods;
	}

	public String toCode(Node astNode)
	{
		String code=null;
		try{
			StringWriter writer = new StringWriter();
			ReWriteVisitor reVisitor = new ReWriteVisitor(writer, "");
			astNode.accept(reVisitor);
			code = writer.toString();
		}catch(StringIndexOutOfBoundsException siobe){
	        System.out.println("invalid input" );
	        siobe.printStackTrace();
	    }
		
		return code;
	}
	
	@Override
	public Object visitAliasNode(AliasNode arg0) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public Object visitAndNode(AndNode arg0) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public Object visitArgsCatNode(ArgsCatNode arg0) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public Object visitArgsNode(ArgsNode arg0) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public Object visitArgsPushNode(ArgsPushNode arg0) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public Object visitArgumentNode(ArgumentNode arg0) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public Object visitArrayNode(ArrayNode arg0) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public Object visitAttrAssignNode(AttrAssignNode arg0) {
		/*if(getCfg()!=null)
		{
			getCfgNode().setClassName(className);
			getCfgNode().setMethodName(methodName);
			getCfgNode().setMvc(mvc);
			setCode(getCode()+"\n"+toCode(arg0));
			System.out.println("attr: "+getCode());
		}*/
		return true;
	}

	@Override
	public Object visitBackRefNode(BackRefNode arg0) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public Object visitBeginNode(BeginNode arg0) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public Object visitBignumNode(BignumNode arg0) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public Object visitBlockArg18Node(BlockArg18Node arg0) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public Object visitBlockArgNode(BlockArgNode arg0) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public Object visitBlockNode(BlockNode arg0) {
		for(int i=0; i<arg0.size(); i++)
		{
			visit(arg0.get(i));
		}
		return true;
	}

	@Override
	public Object visitBlockPassNode(BlockPassNode arg0) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public Object visitBreakNode(BreakNode arg0) {
		/*if(getCfg()!=null)
		{
			getCfgNode().setClassName(className);
			getCfgNode().setMethodName(methodName);
			getCfgNode().setMvc(mvc);
			setCode(getCode()+"\n"+toCode(arg0));
			System.out.println("break: "+getCode());
		}*/
		return true;
	}

	@Override
	public Object visitCallNode(CallNode arg0) {
		/*if(getCfg()!=null)
		{
			getCfgNode().setClassName(className);
			getCfgNode().setMethodName(methodName);
			getCfgNode().setMvc(mvc);
			setCode(getCode()+"\n"+toCode(arg0));
			System.out.println("call: "+getCode());
		}*/
		return true;
	}

	@Override
	public Object visitCaseNode(CaseNode arg0) {
		/*setCfgNode(new CFGNode());
		getCfgNode().setClassName(className);
		getCfgNode().setMethodName(methodName);
		getCfgNode().setMvc(mvc);
		getCfgNode().setCode(toCode(arg0.getCase()));
		cfg.addNodes(getCfgNode());*/
		
		return null;
	}

	@Override
	public Object visitClassNode(ClassNode arg0) {
		if(getCfg()!=null)
		{
			if(getCfgNode()!=null)
			{
				getCfgNode().setClassName(className);
				getCfgNode().setMethodName(methodName);
				getCfgNode().setMvc(mvc);
				System.out.println(className+","+methodName+":"+getCode());
				getCfgNode().setCode(getCode());

				cfg.addCFGNode(getCfgNode());
			}
			setCfgNode(new CFGNode());
			getCfgNode().setClassName(className);
			getCfgNode().setMethodName(methodName);
			getCfgNode().setMvc(mvc);
			getCfgNode().setCode("Exit Node");
			getCfg().addNodes(getCfgNode());
			storage.addCfgFile(fileName+";"+methodName, getCfg());
		}
		setMethods(new ArrayList<Method>());
		setCode("");
		RubyVisitor.className = arg0.getCPath().getLexicalName();
		if(arg0.getBody()!=null)
			visit(arg0.getBody());
		return true;
	}

	@Override
	public Object visitClassVarAsgnNode(ClassVarAsgnNode arg0) {
		/*if(getCfg()!=null)
		{
			getCfgNode().setClassName(className);
			getCfgNode().setMethodName(methodName);
			getCfgNode().setMvc(mvc);
			setCode(getCode()+"\n"+toCode(arg0));
			System.out.println("classvar: "+getCode());
		}*/
		return true;
	}

	@Override
	public Object visitClassVarDeclNode(ClassVarDeclNode arg0) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public Object visitClassVarNode(ClassVarNode arg0) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public Object visitColon2Node(Colon2Node arg0) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public Object visitColon3Node(Colon3Node arg0) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public Object visitCommentNode(CommentNode arg0) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public Object visitConstDeclNode(ConstDeclNode arg0) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public Object visitConstNode(ConstNode arg0) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public Object visitDAsgnNode(DAsgnNode arg0) {
		/*if(getCfg()!=null)
		{
			getCfgNode().setClassName(className);
			getCfgNode().setMethodName(methodName);
			getCfgNode().setMvc(mvc);
			setCode(getCode()+"\n"+toCode(arg0));
			System.out.println("dasgn: "+getCode());
		}*/
		return true;
	}

	@Override
	public Object visitDRegxNode(DRegexpNode arg0) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public Object visitDStrNode(DStrNode arg0) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public Object visitDSymbolNode(DSymbolNode arg0) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public Object visitDVarNode(DVarNode arg0) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public Object visitDXStrNode(DXStrNode arg0) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public Object visitDefinedNode(DefinedNode arg0) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public Object visitDefnNode(DefnNode arg0) {
		//System.out.println("defn code: "+getCfgNode().getCode());
		//System.out.println(getCfgNode().getClassName()+","+getCfgNode().getMethodName()+":"+getCode());
		if(getCfg()!=null)
		{
			/*if(getCfgNode()!=null)
			{
				getCfgNode().setClassName(className);
				getCfgNode().setMethodName(methodName);
				getCfgNode().setMvc(mvc);
				System.out.println(className+","+methodName+":"+getCode());
				getCfgNode().setCode(getCode());
				if(!getCfg().isExist(getCfgNode()))
				{
					getCfg().addNodes(getCfgNode());
				}
			}*/
			setCfgNode(new CFGNode());
			getCfgNode().setClassName(className);
			getCfgNode().setMethodName(methodName);
			getCfgNode().setMvc(mvc);
			getCfgNode().setCode("Exit Node");
			getCfg().addNodes(getCfgNode());
			storage.addCfgFile(fileName+";"+methodName, getCfg());
		}
		setCode("");
		setCfg(new ControlFlowGraph());
		setCfgNode(new CFGNode());
		RubyVisitor.methodName = arg0.getLexicalName();
		getCfg().getEntryNode().setClassName(className);
		getCfg().getEntryNode().setMethodName(methodName);
		getCfg().getEntryNode().setMvc(mvc);
		System.out.println("entry"+className+","+methodName+":"+getCode());
		method = new Method(methodName, fileName, false);
		methods.add(method);
		storage.addMethodList(key, getMethods());
		if(arg0.getBody()!=null)
			visit(arg0.getBody());
		return true;
	}

	@Override
	public Object visitDefsNode(DefsNode arg0) {
		if(getCfg()!=null)
		{
			setCfgNode(new CFGNode());
			getCfgNode().setClassName(className);
			getCfgNode().setMethodName(methodName);
			getCfgNode().setMvc(mvc);
			System.out.println(className+","+methodName+":"+getCode());
			getCfgNode().setCode("Exit Node");
			getCfg().addNodes(getCfgNode());
			storage.addCfgFile(fileName+";"+methodName, getCfg());
		}
		RubyVisitor.methodName = arg0.getLexicalName();
		setCode("");
		setCfg(new ControlFlowGraph());
		setCfgNode(new CFGNode());
		getCfg().getEntryNode().setClassName(className);
		getCfg().getEntryNode().setMethodName(methodName);
		getCfg().getEntryNode().setMvc(mvc);
		method = new Method(methodName, fileName, false);
		methods.add(method);
		storage.addMethodList(key, getMethods());
		if(arg0.getBody()!=null)
			visit(arg0.getBody());
		return true;
	}

	@Override
	public Object visitDotNode(DotNode arg0) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public Object visitEncodingNode(EncodingNode arg0) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public Object visitEnsureNode(EnsureNode arg0) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public Object visitEvStrNode(EvStrNode arg0) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public Object visitFCallNode(FCallNode arg0) {
		/*if(getCfg()!=null)
		{
			getCfgNode().setClassName(className);
			getCfgNode().setMethodName(methodName);
			getCfgNode().setMvc(mvc);
			setCode(getCode()+"\n"+toCode(arg0));
			System.out.println("fcall: "+getCode());
		}*/
		
		return true;
	}

	@Override
	public Object visitFalseNode(FalseNode arg0) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public Object visitFixnumNode(FixnumNode arg0) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public Object visitFlipNode(FlipNode arg0) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public Object visitFloatNode(FloatNode arg0) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public Object visitForNode(ForNode arg0) {
		if(getCfg()!=null && getCfgNode()!=null)
		{
			getCfgNode().setClassName(className);
			getCfgNode().setMethodName(methodName);
			getCfgNode().setMvc(mvc);
			setCode(getCode()+"\n"+toCode(arg0.getIter()));
			getCfgNode().setCode(getCode());
			cfg.addCFGNode(getCfgNode());
		}
		return true;
	}

	@Override
	public Object visitGlobalAsgnNode(GlobalAsgnNode arg0) {
		/*if(getCfg()!=null)
		{
			getCfgNode().setClassName(className);
			getCfgNode().setMethodName(methodName);
			getCfgNode().setMvc(mvc);
			setCode(getCode()+"\n"+toCode(arg0));
			System.out.println("globalsgn: "+getCode());
		}*/
		return true;
	}

	@Override
	public Object visitGlobalVarNode(GlobalVarNode arg0) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public Object visitHashNode(HashNode arg0) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public Object visitIfNode(IfNode arg0) {
		if(getCfg()!=null && getCfgNode()!=null)
		{
			getCfgNode().setClassName(className);
			getCfgNode().setMethodName(methodName);
			getCfgNode().setMvc(mvc);
			setCode(getCode()+"\n"+toCode(arg0.getCondition()));
			getCfgNode().setCode(getCode());
			cfg.addCFGNode(getCfgNode());
		}
		/*if(getCfgNode()==null)
		{
			getCfgNode().setClassName(className);
			getCfgNode().setMethodName(methodName);
			getCfgNode().setMvc(mvc);
			getCfgNode().setCode(toCode(arg0.getCondition()));
			getCfg().addNodes(getCfgNode());
		}
		setCode(getCode()+"\n"+toCode(arg0.getCondition()));
		getCfgNode().setCode(getCode());
		getCfg().addNodes(getCfgNode());
		setCfgNode(new CFGNode());
		
		if(arg0.getThenBody()!=null)
		{
			setCfgNode(new CFGNode());
			getCfgNode().setClassName(className);
			getCfgNode().setMethodName(methodName);
			getCfgNode().setMvc(mvc);
			getCfgNode().setCode(toCode(arg0.getThenBody()));
			getCfg().addNodes(getCfgNode());
		}
		if(arg0.getElseBody()!=null)
		{
			setCfgNode(new CFGNode());
			getCfgNode().setClassName(className);
			getCfgNode().setMethodName(methodName);
			getCfgNode().setMvc(mvc);
			getCfgNode().setCode(toCode(arg0.getElseBody()));
			getCfg().addNodes(getCfgNode());
		}*/
		return null;
	}

	@Override
	public Object visitImplicitNilNode(ImplicitNilNode arg0) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public Object visitInstAsgnNode(InstAsgnNode arg0) {
		/*if(getCfg()!=null)
		{
			getCfgNode().setClassName(className);
			getCfgNode().setMethodName(methodName);
			getCfgNode().setMvc(mvc);
			setCode(getCode()+"\n"+toCode(arg0));
			System.out.println("instasgn: "+getCode());
		}*/
		return true;
	}

	@Override
	public Object visitInstVarNode(InstVarNode arg0) {
		return null;
	}

	@Override
	public Object visitIterNode(IterNode arg0) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public Object visitKeywordArgNode(KeywordArgNode arg0) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public Object visitKeywordRestArgNode(KeywordRestArgNode arg0) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public Object visitLambdaNode(LambdaNode arg0) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public Object visitListNode(ListNode arg0) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public Object visitLiteralNode(LiteralNode arg0) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public Object visitLocalAsgnNode(LocalAsgnNode arg0) {
		/*if(getCfg()!=null)
		{
			getCfgNode().setClassName(className);
			getCfgNode().setMethodName(methodName);
			getCfgNode().setMvc(mvc);
			setCode(getCode()+"\n"+toCode(arg0));
			System.out.println("localasgn: "+getCode());
		}*/
		return true;
	}

	@Override
	public Object visitLocalVarNode(LocalVarNode arg0) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public Object visitMatch2Node(Match2Node arg0) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public Object visitMatch3Node(Match3Node arg0) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public Object visitMatchNode(MatchNode arg0) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public Object visitMethodNameNode(MethodNameNode arg0) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public Object visitModuleNode(ModuleNode arg0) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public Object visitMultipleAsgnNode(MultipleAsgnNode arg0) {
		/*if(getCfg()!=null)
		{
			getCfgNode().setClassName(className);
			getCfgNode().setMethodName(methodName);
			getCfgNode().setMvc(mvc);
			setCode(getCode()+"\n"+toCode(arg0));
		}*/
		return true;
	}

	@Override
	public Object visitNewlineNode(NewlineNode arg0) {
		Node node = arg0.getNextNode();
		if(getCfg()!=null &&(node.getNodeType().equals(NodeType.ATTRASSIGNNODE)||node.getNodeType().equals(NodeType.BREAKNODE) ||
				node.getNodeType().equals(NodeType.CALLNODE) || node.getNodeType().equals(NodeType.CLASSVARASGNNODE)
						||node.getNodeType().equals(NodeType.DASGNNODE)||node.getNodeType().equals(NodeType.FCALLNODE)
						||node.getNodeType().equals(NodeType.GLOBALASGNNODE) || node.getNodeType().equals(NodeType.INSTASGNNODE)
						||node.getNodeType().equals(NodeType.LOCALASGNNODE)||node.getNodeType().equals(NodeType.MULTIPLEASGNNODE)
						||node.getNodeType().equals(NodeType.RETURNNODE)||node.getNodeType().equals(NodeType.VCALLNODE)
						||node.getNodeType().equals(NodeType.CALLNODE)))
		{
			getCfgNode().setClassName(className);
			getCfgNode().setMethodName(methodName);
			getCfgNode().setMvc(mvc);
			setCode(getCode()+"\n"+toCode(node));
		}
		else if(getCfg()!=null && node.getNodeType().equals(NodeType.IFNODE)||node.getNodeType().equals(NodeType.FORNODE)||
				node.getNodeType().equals(NodeType.WHILENODE)||node.getNodeType().equals(NodeType.CASENODE)||
				node.getNodeType().equals(NodeType.UNTILNODE))
		{
			visit(node);
		}
		else visit(node);
		return true;
	}

	@Override
	public Object visitNextNode(NextNode arg0) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public Object visitNilNode(NilNode arg0) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public Object visitNotNode(NotNode arg0) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public Object visitNthRefNode(NthRefNode arg0) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public Object visitOpAsgnAndNode(OpAsgnAndNode arg0) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public Object visitOpAsgnNode(OpAsgnNode arg0) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public Object visitOpAsgnOrNode(OpAsgnOrNode arg0) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public Object visitOpElementAsgnNode(OpElementAsgnNode arg0) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public Object visitOptArgNode(OptArgNode arg0) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public Object visitOrNode(OrNode arg0) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public Object visitPostExeNode(PostExeNode arg0) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public Object visitPreExeNode(PreExeNode arg0) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public Object visitRedoNode(RedoNode arg0) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public Object visitRegexpNode(RegexpNode arg0) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public Object visitRescueBodyNode(RescueBodyNode arg0) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public Object visitRescueNode(RescueNode arg0) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public Object visitRestArgNode(RestArgNode arg0) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public Object visitRetryNode(RetryNode arg0) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public Object visitReturnNode(ReturnNode arg0) {
		/*if(getCfg()!=null)
		{
			getCfgNode().setClassName(className);
			getCfgNode().setMethodName(methodName);
			getCfgNode().setMvc(mvc);
			setCode(getCode()+"\n"+toCode(arg0));
		}*/
		return true;
	}

	@Override
	public Object visitRootNode(RootNode arg0) {
		//storage.addMethodList(key, methodName);
		visit(arg0.getBody());
		return true;
	}

	@Override
	public Object visitSClassNode(SClassNode arg0) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public Object visitSValueNode(SValueNode arg0) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public Object visitSelfNode(SelfNode arg0) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public Object visitSplatNode(SplatNode arg0) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public Object visitStrNode(StrNode arg0) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public Object visitSuperNode(SuperNode arg0) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public Object visitSymbolNode(SymbolNode arg0) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public Object visitSyntaxNode(SyntaxNode arg0) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public Object visitToAryNode(ToAryNode arg0) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public Object visitTrueNode(TrueNode arg0) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public Object visitUnaryCallNode(UnaryCallNode arg0) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public Object visitUndefNode(UndefNode arg0) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public Object visitUntilNode(UntilNode arg0) {
		if(getCfg()!=null && getCfgNode()!=null)
		{
			getCfgNode().setClassName(className);
			getCfgNode().setMethodName(methodName);
			getCfgNode().setMvc(mvc);
			setCode(getCode()+"\n"+toCode(arg0.getCondition()));
			getCfgNode().setCode(getCode());
			cfg.addCFGNode(getCfgNode());
		}
		return true;
	}

	@Override
	public Object visitVAliasNode(VAliasNode arg0) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public Object visitVCallNode(VCallNode arg0) {
		/*if(getCfg()!=null)
		{
			getCfgNode().setClassName(className);
			getCfgNode().setMethodName(methodName);
			getCfgNode().setMvc(mvc);
			setCode(getCode()+"\n"+toCode(arg0));
			System.out.println("vcall: "+getCode());
		}*/
		return true;
	}

	@Override
	public Object visitWhenNode(WhenNode arg0) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public Object visitWhileNode(WhileNode arg0) {
		if(getCfg()!=null && getCfgNode()!=null)
		{
			getCfgNode().setClassName(className);
			getCfgNode().setMethodName(methodName);
			getCfgNode().setMvc(mvc);
			setCode(getCode()+"\n"+toCode(arg0.getCondition()));
			getCfgNode().setCode(getCode());
			cfg.addCFGNode(getCfgNode());
		}
		/*if(getCfgNode()==null)
		{
			getCfgNode().setClassName(className);
			getCfgNode().setMethodName(methodName);
			getCfgNode().setMvc(mvc);
			getCfgNode().setCode(toCode(arg0.getCondition()));
			getCfg().addNodes(getCfgNode());
		}
		/*System.out.println("getcode di while: "+getCode());
		System.out.println("cond di while: "+toCode(arg0.getCondition()));
		setCode(getCode()+"\n"+toCode(arg0.getCondition()));
		System.out.println("getcodeplus di while: "+getCode());*//*
		getCfgNode().setCode(getCode());
		getCfg().addNodes(getCfgNode());
		setCfgNode(new CFGNode());
		
		if(arg0.getBody()!=null)
		{
			//System.out.println("body while: "+toCode(arg0.getBody()));
			setCfgNode(new CFGNode());
			getCfgNode().setClassName(className);
			getCfgNode().setMethodName(methodName);
			getCfgNode().setMvc(mvc);
			getCfgNode().setCode(toCode(arg0.getBody()));
			getCfg().addNodes(getCfgNode());
		}
		else
			visit(arg0.getBody());*/
		return true;
	}

	@Override
	public Object visitXStrNode(XStrNode arg0) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public Object visitYieldNode(YieldNode arg0) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public Object visitZArrayNode(ZArrayNode arg0) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public Object visitZSuperNode(ZSuperNode arg0) {
		// TODO Auto-generated method stub
		return null;
	}
}
